import java.util.Arrays;

public class Main {
    public static void main(String[] args) {

//        int[] arr = {1,2,3,4,5,6,7,8,9,10};
//        int key = 5;
//        int index = binarySearch(arr,key);
//        System.out.println("Index of " + key + " is " + index);

//        int[] arr = {1,10,2,9,3,8,4,7,5,6};
//        bubbleSort(arr);
//        System.out.println(Arrays.toString(arr));

//        int[] arr1 = {2,2,3,3,3,3,1};
//        int n = majorityElement(arr1);
//        System.out.println("Majority Element is " + n);

        int[] arr2 = {1,2,3,4,5,6,7,8,9,10};
        func4(arr2);
        System.out.println(Arrays.toString(arr2));

    }

    public static void func4(int[] arr) {
        int i=0;
        int j=arr.length-1;
        while(i<j) {
            while (i < j && arr[i] % 2 != 0) {
                i++;
            }
            while (i < j && arr[j] % 2 == 0) {
                j--;
            }
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
    }
    public static int majorityElement(int[] nums) {
        Arrays.sort(nums);
        return nums[nums.length/2];
    }

    public static void bubbleSort(int[] arr) {
        boolean flag = true;
        for(int i=0; i<arr.length-1; i++)
        {
            for(int j=0; j<arr.length-i-1; j++)
                if(arr[j] > arr[j+1]) {
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                    flag = false;
                }
            if(flag==true)
                break;
        }
    }
    public static int binarySearch(int[] arr, int key) {
        int left = 0;
        int right = arr.length - 1;
        while (left <= right) {
            int mid = (left + right) / 2;
            if (arr[mid]==key)
                return mid;
            else if (arr[mid] < key)
                left = mid + 1;
            else
                right = mid - 1;
        }
        return -1;

    }
}